package com.aaa.sbms.service;

import com.aaa.sbms.dao.GroupDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class GroupServiceImpl implements GroupService {

    @Autowired(required = false)
    private GroupDao groupDao;

    @Override
    public Map depts() {
        Map resultMap = new HashMap();
        List<Map> list = groupDao.depts();
        resultMap.put("list",list);
        return resultMap;
    }

    @Override
    public Map users() {
        Map resultMap = new HashMap();
        List<Map> list = groupDao.users();
        resultMap.put("list",list);
        return resultMap;
    }

    @Override
    public Map page(Map map) {
        int pageNo = Integer.valueOf(map.get("pageNo").toString());
        int pageSize = Integer.valueOf(map.get("pageSize").toString());
        int begin = (pageNo-1)*pageSize;
        map.put("begin",begin);
        map.put("pageSize",pageSize);
        List<Map> page = groupDao.page(map);
        int total = groupDao.pageCount(map);
        Map resultMap= new HashMap();
        resultMap.put("list",page);
        resultMap.put("total",total);
        return resultMap;
    }

    @Override
    public Map groupOne(int groupid) {
        Map resultMap = new HashMap();
        Map map = groupDao.groupOne(groupid);
        resultMap.put("list",map);
        return resultMap;
    }

    @Override
    public int add(Map map) {
        return groupDao.add(map);
    }

    @Override
    public int update(Map map) {
        return groupDao.update(map);
    }

    @Override
    public int delete(int groupid) {
        return groupDao.delete(groupid);
    }
}
